package util;

import java.awt.Color;
import java.util.ArrayList;

import networkInterface.*;

import object.Connection;
import object.Node;

public class ConnectionUtil {
	public static Color getBetterConnectionColor(Connection c){
		return getBetterConnection(c).getDefaultColor();
	}
	/**
	 * Gets the connection that is 'better' than the other(higher priority)
	 * @param c
	 * @return
	 */
	public static NetworkInterfaceBase getBetterConnection(Connection c){
		NetworkInterfaceBase netInt = null;
		if(c.getInterfaces()[0] instanceof WifiInterfaceBase){
			if(c.getInterfaces()[0] instanceof SimpleSmallWifiInterface){
				netInt = c.getInterfaces()[0];
			}
			if(c.getInterfaces()[1] instanceof SimpleSmallWifiInterface){
				netInt = c.getInterfaces()[1];
			}
			
			if(c.getInterfaces()[0] instanceof SimpleMediumWifiInterface){
				netInt = c.getInterfaces()[0];
			}
			if(c.getInterfaces()[1] instanceof SimpleMediumWifiInterface){
				netInt = c.getInterfaces()[1];
			}
		}
		if(c.getInterfaces()[0] instanceof PhoneInterfaceBase){
			if(c.getInterfaces()[0] instanceof Phone3GInterface){
				netInt = c.getInterfaces()[0];
			}
			if(c.getInterfaces()[1] instanceof Phone3GInterface){
				netInt = c.getInterfaces()[1];
			}
			
			if(c.getInterfaces()[0] instanceof Tower3GInterface){
				netInt = c.getInterfaces()[0];
			}
			if(c.getInterfaces()[1] instanceof Tower3GInterface){
				netInt = c.getInterfaces()[1];
			}
		}
		return netInt;
	}
	public static void resetAllConnectionsColor(ArrayList<Node> nodes){
		for(Node n : nodes){
			for(Connection c : n.getConnections()){
				c.color = c.getDefaultColor();
			}
		}
	}
}
